{% extends "base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% load static %}
{% load ietf_filters %}
{% load person_filters %}
{% load textfilters %}
{% block title %}{{ doc.title }}{% endblock %}
{% block content %}
    {% origin %}
    {{ top|safe }}
    {% include "doc/revisions_list.html" %}
    <div id="doc-timeline"></div>
    {% if doc.rev != latest_rev %}
        <div class="alert alert-warning my-3">The information below is for an old version of the document.</div>
    {% endif %}
    <table class="table table-sm table-borderless">
        <tbody class="meta border-top">
            <tr>
                <th scope="row">Document</th>
                <th scope="row">
                    {% if doc.get_state_slug not in approved_states %}
                        Proposed status change
                    {% else %}
                        Status change
                    {% endif %}
                </th>
                <td class="edit">
                    {% if not snapshot and user|has_role:"Area Director,Secretariat" and doc.get_state_slug not in approved_states %}
                        <a class="btn btn-primary btn-sm float-end"
                           href="{% url 'ietf.doc.views_status_change.edit_title' name=doc.name %}">
                            Edit
                        </a>
                    {% endif %}
                </td>
                <th scope="row">
                    {{ doc.title }}
                    {% if snapshot %}<span class="badge rounded-pill text-bg-warning">Snapshot</span>{% endif %}
                </th>
            </tr>
            <tr>
                <td></td>
                <th scope="row">Last updated</th>
                <td class="edit"></td>
                <td>{{ doc.time|date:"Y-m-d" }}</td>
            </tr>
            {% regroup sorted_relations by relationship.name as relation_groups %}
            {% for relation_group in relation_groups %}
                <tr>
                    <td></td>
                    <th scope="row">{{ relation_group.grouper }}</th>
                    <td class="edit"></td>
                    <td>
                        {% for rel in relation_group.list %}
                            {{ rel.target.name|upper|urlize_ietf_docs }}{% if not forloop.last %},{% endif %}
                        {% endfor %}
                    </td>
                </tr>
            {% endfor %}
            <tr>
                <td></td>
                <th scope="row">
                    <a href="{% url 'ietf.doc.views_help.state_help' type="status-change" %}">State</a>
                </th>
                <td class="edit">
                    {% if not snapshot and user|has_role:"Area Director,Secretariat" %}
                        <a class="btn btn-primary btn-sm float-end"
                           href="{% url "ietf.doc.views_status_change.change_state" name=doc.name %}">
                            Edit
                        </a>
                    {% endif %}
                </td>
                <td>
                    <span title="{{ doc.get_state.desc }}">{{ doc.get_state.name }}</span>
                </td>
            </tr>
        </tbody>
        <tbody class="meta border-top">
            <tr>
                <th scope="row">IESG</th>
                <th scope="row">Telechat date</th>
                <td class="edit">
                    {% if not snapshot and user|has_role:"Area Director,Secretariat" and doc.get_state_slug not in approved_states %}
                        <a class="btn btn-primary btn-sm float-end"
                           href="{% url 'ietf.doc.views_doc.telechat_date;status-change' name=doc.name %}">
                            Edit
                        </a>
                    {% endif %}
                </td>
                <td>
                    {% if not telechat %}
                        <span class="text-body-secondary">(None)</span>
                    {% else %}
                        On agenda of {{ telechat.telechat_date|date:"Y-m-d" }} IESG telechat
                        {% if doc.returning_item %}(returning item){% endif %}
                    {% endif %}
                    {% if ballot_summary %}
                        <br>
                        <i>{{ ballot_summary }}</i>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td></td>
                <th scope="row">Responsible AD</th>
                <td class="edit">
                    {% if not snapshot and user|has_role:"Area Director,Secretariat" and doc.get_state_slug not in approved_states %}
                        <a class="btn btn-primary btn-sm float-end"
                           href="{% url 'ietf.doc.views_status_change.edit_ad' name=doc.name %}">
                            Edit
                        </a>
                    {% endif %}
                </td>
                <td>{% person_link doc.ad %}</td>
            </tr>
            <tr>
                <td></td>
                <th scope="row">Send notices to</th>
                <td class="edit">
                    {% if not snapshot and user|has_role:"Area Director,Secretariat" and doc.get_state_slug not in approved_states %}
                        <a class="btn btn-primary btn-sm float-end"
                           href="{% url 'ietf.doc.views_doc.edit_notify;status-change' name=doc.name %}">
                            Edit
                        </a>
                    {% endif %}
                </td>
                <td>
                    {{ doc.notify|linkify }}
                </td>
            </tr>
        </tbody>
    </table>
    <p class="buttonlist">
        {% if not snapshot and user|has_role:"Area Director,Secretariat" %}
            {% if doc.get_state_slug not in approved_states %}
                <a class="btn btn-primary"
                   href="{% url 'ietf.doc.views_status_change.edit_relations' name=doc.name %}">
                    Edit affected RFCs
                </a>
                <a class="btn btn-primary"
                   href="{% url 'ietf.doc.views_status_change.last_call'  name=doc.name %}">
                    Edit last call text
                </a>
            {% endif %}
            {% if doc.get_state_slug != 'apprsent' %}
                <a class="btn btn-primary"
                   href="{% url 'ietf.doc.views_status_change.submit' name=doc.name %}">
                    Edit status change text
                </a>
            {% endif %}
        {% endif %}
        {% if request.user|has_role:"Secretariat" and doc.get_state_slug == 'appr-pend' %}
            <a class="btn btn-warning"
               href="{% url 'ietf.doc.views_status_change.approve' name=doc.name %}">
                Approve RFC status change
            </a>
        {% endif %}
    </p>
    {% if doc.rev %}
        <div class="card mt-5">
            <div class="card-header">
                {{ doc.name }}-{{ doc.rev }}
            </div>
            <div class="card-body">
                <pre>{{ content|maybewordwrap|urlize_ietf_docs|linkify }}</pre>
            </div>
        </div>
    {% endif %}
{% endblock %}
{% block js %}
    <script src="{% static 'ietf/js/d3.js' %}">
    </script>
    <script src="{% static 'ietf/js/document_timeline.js' %}">
    </script>
{% endblock %}